// /**
//  * Created by Void on 2017/9/19.
//  */
//
// import {PointerCoordinates, pointerCoord} from "ionic-angular/es2015/util/dom";
// import {Renderer2, ElementRef} from "@angular/core";
// import {Platform} from "ionic-angular/index";
// import {SuperTabsConfig} from "./super-tabs";
//
// export class SuperTabsPanGesture{
//
//     onMove:(delta:number) => void;
//     onEnd:(shortSwipe:boolean,shortSwipeDelta?:number) => void;
//
//     private initialCoords:PointerCoordinates;
//     private initialTimestamp:number;
//     private leftThreshold:number = 0; // 左边拖动开始的临界值  设置临界值的目的 是 为了 防止和 侧滑 冲突
//     private rightThreshold:number = 0; // 右边拖动开始的临界值 在两个临界值中间的区域 允许被拖动
//     private shouldCapture:boolean;
//     private isDragging:boolean;
//     private lastPosX:number;
//     private listeners:Function[] = [];
//
//     constructor(
//         private rnd:Renderer2,
//         private el:ElementRef,
//         private plt:Platform,
//         private config:SuperTabsConfig
//     ){
//         this.listeners.push(
//             rnd.listen(el,'touchstart',this._onstart.bind(this)),
//             rnd.listen(el,'touchmove',this._onMove.bind(this)),
//             rnd.listen(el,'touchend',this._onEnd.bind(this)),
//         )
//     }
//
//     destroy() {
//         this.listeners.forEach(fn => fn());
//     }
//
//     private _onstart(ev:TouchEvent){
//         const coords:PointerCoordinates = pointerCoord(ev),
//             vw = this.plt.width();
//         if (coords.x < this.leftThreshold || coords.x > vw - this.rightThreshold){
//             // 不在拖动开始的区域范围内 忽略拖动
//             this.shouldCapture = false;
//             return;
//         }
//
//         this.initialCoords = coords;
//         if (this.config.shortSwipeDuration > 0) this.initialTimestamp = Date.now();
//         this.lastPosX = coords.x;
//     }
//     private _onMove(ev:TouchEvent){
//         const coords:PointerCoordinates = pointerCoord(ev);
//         if (!this.isDragging){
//             if (typeof this.shouldCapture !== 'boolean') this.checkGesture(coords);
//             if (this.shouldCapture === true){
//                 this.isDragging = true;
//             }else {
//                 return;
//             }
//         }
//         ev.stopPropagation(); // 禁止事件冒泡
//         ev.preventDefault();  // 取消事件的默认动作
//
//         // 获取移动的X距离
//         const deltaX:number = this.lastPosX - coords;
//
//         this.onMove && this.onMove(deltaX);
//
//         this.lastPosX = coords.x;
//     }
//     private _onEnd(ev:TouchEvent){
//         const coords:PointerCoordinates = pointerCoord(ev);
//
//         if (this.shouldCapture === true){
//             if (this.config.shortSwipeDuration > 0){
//                 const deltaTime:number = Date.now() - this.initialTimestamp;
//
//                 if (deltaTime <= this.config.shortSwipeDuration){
//                     this.onEnd && this.onEnd(true,coords.x - this.initialCoords.x);
//                 }else {
//                     this.onEnd && this.onEnd(false);
//                 }
//             }else {
//                 this.onEnd && this.onEnd(false);
//             }
//         }
//         this.isDragging = false;
//         this.shouldCapture = undefined;
//     }
//
//     private checkGesture(newCoords:PointerCoordinates){
//         const radians = this.config.maxDragAngle * (Math.PI/180),
//             maxCosine = Math.cos(radians),
//             deltaX = newCoords.x - this.initialCoords.x,
//             deltaY = newCoords.y - this.initialCoords.y,
//             distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
//         if (distance >= this.config.dragThreshold){
//             const angle = Math.atan2(deltaY,deltaX),
//                 cosine = Math.cos(angle);
//             this.shouldCapture = Math.abs(cosine) > maxCosine;
//         }
//     }
// }